﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Golos.Helper
{
    public class Topology
    {
        public static string GetEndPoint(string topologyFileName)
        {
            List<string> endPoints = new List<string>();
            using (FileStream stream = new FileStream(topologyFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        string endPoint = reader.ReadLine();
                        if(string.IsNullOrEmpty(endPoint))
                            continue;
                        endPoints.Add(endPoint);
                    }
                }
            }
            if (endPoints.Count == 0)
                return null;
            Random random = new Random(10000);
            return endPoints[random.Next(0, endPoints.Count - 1)];
        }
    }
}
